import { HintBtnView } from "../mapUI/HintBtnView";
import { LayerManager } from "../../manager/LayerManager";
import { RightTopLayerLine } from "../../manager/RightTopLayerLine";
import { RightTopLayerIndex } from "../../manager/RightTopLayerIndex";
import { ObjCreate } from "../common/ObjCreate";
import { ResFileConst } from "../../resource/ResFileConst";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { SecTimer } from "../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../com/gengine/core/frame/TimerType";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
import { SecTimerView } from "../common/SecTimerView";
type int = number;
//class CrossMainCityIcon
    
    export  class CrossMainCityIcon extends HintBtnView
    {
        constructor()
        {
            super();
            this.layer = LayerManager.rightTopUILayer;
            this.line = RightTopLayerLine.lineOne;
            this.index = RightTopLayerIndex.CrossMainCityIcon;
            this.initUI();
            return;
        }

        protected initUI(): void
        {
            this._btn = ObjCreate.createGLoadedButton(ResFileConst.CrossMainCityIcon, 0, 0, 60, 50, this);
            return;
        }

        /* internal  */createSecTimerView(): void
        {
            this._secView = ObjCreate.createSecTimeView(HTMLUtil.addColor("hh: mm: ss", GlobalStyle.color1), -10, 50, 80, 20, this, new GTextFormat(FontUtil.defaultName, 12, 16776960, null, null, null, null, null, flash.text.TextFormatAlign.CENTER));
            this._secView.timeOutHandler = this.disposeCountDown;
            this._secView.filters = [FilterConst.glowFilter];
            return;
        }

        public setCountDown(arg1: int): void
        {
            if (arg1 > this.Gap) 
            {
                if (!this._secTimer) 
                {
                    this._secTimer = new SecTimer();
                    this._secTimer.addListener(TimerType.COMPLETE, this.onSecTimerComplete);
                }
                this._secTimer.repeatCount = arg1 - this.Gap;
                this._secTimer.start();
            }
            else 
            {
                this.startCountDown(arg1);
            }
            return;
        }

        /* internal  */onSecTimerComplete(arg1): void
        {
            if (this._secTimer) 
            {
                this._secTimer.dispose();
                this._secTimer = null;
            }
            this.startCountDown(this.Gap);
            return;
        }

        /* internal  */startCountDown(arg1: int): void
        {
            if (!this._secView) 
            {
                this.createSecTimerView();
            }
            this._secView.setLeftTime(arg1);
            this.show();
            return;
        }

        public disposeCountDown(): void
        {
            if (this._secTimer) 
            {
                this._secTimer.dispose();
                this._secTimer = null;
            }
            if (this._secView) 
            {
                if (this._secView.parent) 
                {
                    this._secView.parent.removeChild(this._secView);
                }
                this._secView.dispose();
                this._secView = null;
            }
            return;
        }

        public get running(): Boolean
        {
            if (this._secTimer && this._secTimer.running) 
            {
                return true;
            }
            if (this._secView && this._secView.running) 
            {
                return true;
            }
            return false;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this.disposeCountDown();
            return;
        }

        /* internal */ /* const */Gap: int=600;

        /* internal */ /* var */_btn: GLoadedButton;

        /* internal */ /* var */_secView: SecTimerView;

        /* internal */ /* var */_secTimer: SecTimer;
    }
